<style type="text/css">
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <selectSearch :selectBaseInfo="selectBaseInfo" @post-data="getCompentensData"></selectSearch>
        <Form-item label="请假开始时间">
            <Row>
                <i-col>
                    <Date-picker type="datetime" placeholder="选择开始日期"  @on-change="changeStartDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="请假结束时间">
            <Row>
                <i-col>
                    <Date-picker size="large"  type="datetime" placeholder="选择结束日期" @on-change="changeEndDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="backGoJump()" style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import selectSearch from '../../components/selectSearch';

    export default {
        data() {
            return {
                formValidate: {
                    startDate:"",
                    endDate:'',
                },
                ruleValidate: {},
                //选择人员
                selectBaseInfo: {
                    "title": '选择人员',
                    "placeholder": '请输入姓名',
                    "postUrl": apiUtil.urls.userList,
                    'postType': 'user',
                },
                reqpeopleDept: '',
            }
        },
        mounted: function () {},
        components: {
            selectSearch
        },
        methods: {
            //backJump
            backGoJump:function(){
                this.$router.back(-1)

            },
            changeStartDate: function (date) {
                console.log(date);
                this.formValidate.startDate = date;
            },
            changeEndDate: function (date) {
                console.log(date);
                this.formValidate.endDate = date;
            },
            //添加
            handleSubmit(name) {

                let that = this;
                // let model = this.$refs[name].model;
                // this.$refs[name].validate((valid) => {
                //     that.addData(model);
                // })
                that.addData(that.formValidate);
            },

            //获取选择搜索组件传来结果数据
            getCompentensData: function (value) {
                this.reqpeopleDept = value;
            },

            addData: function (model) {
                let that = this;
                model.peopleId = this.reqpeopleDept.resultId;
                model.teamId = this.$route.query.id;

                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.AddTeamMember, params, function (res) {
                    that.$Loading.finish();
                    that.$Notice.open({
                        title: '通知',
                        desc: '添加成功 ',
                        duration: 0
                    });
                });
            },


        }
    }
</script>
